package com.io;

import org.apache.commons.io.IOUtils;

import java.io.*;

public class ObjectOutputStreamTest {
    public static void main(String[] args) {
        OutputStream os = null;
        ObjectOutputStream oos = null;

        try {
            os = new FileOutputStream("/Users/edy/Desktop/file1/object.txt",true);
            oos = new ObjectOutputStream(os);
            String a = "123123";
            Student student = new Student("zhangsa",10);
            oos.writeObject(a);
            oos.writeObject(student);
            oos.writeObject(null);
            oos.flush(); //一次性写入

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(oos);
            IOUtils.closeQuietly(os);
        }
    }
}
